package cn.hackcloud.netty.basic.bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TimerServiceHandler implements Runnable {
	Socket socket;

	public TimerServiceHandler(Socket socket) {
		super();
		this.socket = socket;
	}

	@Override
	public void run() {
		BufferedReader bufferedReader = null;
		PrintWriter printWriter = null;
		try {
			bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			printWriter = new PrintWriter(socket.getOutputStream(), true);
			String time = null;
			System.out.println("dddd");
			while (true) {
				System.out.println("dddd");
				String readLine = bufferedReader.readLine();
				if(readLine==null) {
					break;
				}
				System.out.println(readLine);
				time = "TIME".equals(readLine) ? System.currentTimeMillis() + "" : "ERROR";
				printWriter.println(time);
				System.out.println(time);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
